.TH std::make_reverse_iterator 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::make_reverse_iterator \- std::make_reverse_iterator

.SH Synopsis
   Defined in header <iterator>
   template< class Iter >                                       \fI(since C++14)\fP
   std::reverse_iterator<Iter> make_reverse_iterator( Iter i    (constexpr since C++17)
   );

   make_reverse_iterator is a convenience function template that constructs a
   std::reverse_iterator for the given iterator i (which must be a
   LegacyBidirectionalIterator) with the type deduced from the type of the argument.

.SH Parameters

   i - iterator to be converted to reverse iterator

.SH Return value

   A std::reverse_iterator constructed from i.

.SH Notes

         Feature-test macro         Value    Std            Feature
   __cpp_lib_make_reverse_iterator 201402L \fI(C++14)\fP std::make_reverse_iterator

.SH Possible implementation

   template<class Iter>
   constexpr std::reverse_iterator<Iter> make_reverse_iterator(Iter i)
   {
       return std::reverse_iterator<Iter>(i);
   }

.SH Example


// Run this code

 #include <algorithm>
 #include <iostream>
 #include <iterator>
 #include <vector>

 int main()
 {
     std::vector<int> v{1, 3, 10, 8, 22};

     std::sort(v.begin(), v.end());
     std::copy(v.begin(), v.end(), std::ostream_iterator<int>(std::cout, ", "));
     std::cout << '\\n';

     std::copy(std::make_reverse_iterator(v.end()),
               std::make_reverse_iterator(v.begin()),
               std::ostream_iterator<int>(std::cout, ", "));
     std::cout << '\\n';
 }

.SH Output:

 1, 3, 8, 10, 22,
 22, 10, 8, 3, 1,

.SH See also

   reverse_iterator iterator adaptor for reverse-order traversal
                    \fI(class template)\fP
   rbegin           returns a reverse iterator to the beginning of a container or array
   crbegin          \fI(function template)\fP
   \fI(C++14)\fP
   rend             returns a reverse end iterator for a container or array
   crend            \fI(function template)\fP
   \fI(C++14)\fP
